﻿@model IEnumerable<GPI.Models.GPI_PROJECT>

@{
    ViewBag.Title = "Liste des groupes";
}

<h2>Index</h2>

<input type="checkbox" id="checkbox" />N'afficher que les projets sans inscrits<br /><br />
<div id="printableArea">
    <table id="tableGroup">
        <tr>
            <th>
                Projet
            </th>
            <th>
                Technologie(s)
            </th>
            <th>
                Client
            </th>
            <th>
                Etudiants
            </th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.title)
            </td>
            <td>
                <ul>
                @foreach (GPI.Models.GPI_TECHNOLOGY techno in item.GPI_TECHNOLOGY)
                     {
                        <li>@techno.name</li>
                     }
                </ul>
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.GPI_PROF1.last_name)
            </td>
            <td>
                <ul>
                 @{
                     foreach (GPI.Models.GPI_STUDENT student in item.GPI_STUDENT)
                     {
                        <li>@student.first_name @student.last_name</li>
                     }
                 }
                 </ul>
            </td>
            @if (item.GPI_STUDENT.Any())
            {
                <td style="display:none;">
                     hideMe
                </td>
            }
        </tr>
    }

    </table>
</div>

<br />
<br />
<input type="button" id="buttonPrint" value="Print" />
<br />
<p>
    @using (Html.BeginForm("Index", "Project"))
    {
        <button type="submit">Retour</button>
    }
</p>

<script type="text/javascript">
    $(document).ready(function () {
        var filter = "hideMe";
        $("#checkbox").click(function () {
            if ($(this).is(":checked")) {
                $("#tableGroup").find("td:contains(" + filter + ")").parent().hide();
            } else {
                $("#tableGroup").find("td:contains(" + filter + ")").parent().show();
            }
        });

        $("#buttonPrint").click(function printDiv() {
            var printContents = document.getElementById("printableArea").innerHTML;
            var originalContents = document.body.innerHTML;

            document.body.innerHTML = printContents;

            window.print();

            document.body.innerHTML = originalContents;
            document.location.reload(false);
        });
    });
    
</script>
